Skip to content

Conversation

@ianks
Copy link
Contributor

@ianks ianks commented Oct 2, 2020

This PR is a spike at adding an optional setTimeout implementation. The current code is very raw, but wanted to post is so I could get some early feedback. Thoughts?

@ianks ianks marked this pull request as draft October 2, 2020 05:39
@SamSaffron
Copy link
Collaborator

SamSaffron commented Oct 2, 2020

We have to be super careful around lifetimes here between the 2 vMs we don't want to segfault cause a context with timeouts got disposed.

I can see people wanting both this and setInterval though I wonder if this scheduling should happen directly in C to avoid depending on Ruby here

Do you have a particular use case here you are blocked on.

Maybe a good opening move here is simply offering some level of interoperability in general?

fn = ctx.eval("function(x) {return 40 + x;}")
puts ctx.call(fn, 2)
=> 42

Ideally the amount of info we leak between VMs though should be minimal. So stuff like this should not segfault or lead to any surprises.

fn = ctx.eval("function(x) {return 40 + x;}")
ctx.dispose
p fn
ctx.call(fn, 2)

@ianks
Copy link
Contributor Author

ianks commented Oct 2, 2020

I can see people wanting both this and setInterval though I wonder if this scheduling should happen directly in C to avoid depending on Ruby here

I was wondering this as well. It seems like there is support in libplatform for an event loop that does this type of thing, but the documentation is scarce. Overall, if it is possible, I do think it is a better approach.

Here are some examples of how others have implemented timers:

If anyone stumble on any information about implementing this in an embedded context, please post it here! The documentation on it is hard to come by.

Do you have a particular use case here you are blocked on.

We are SSR React in our codebase with GraphQL. Having the ability to make those queries async would speed things up a bunch.

Maybe a good opening move here is simply offering some level of interoperability in general?

fn = ctx.eval("function(x) {return 40 + x;}")
puts ctx.call(fn, 2)
=> 42

👍

@ianks
Copy link
Contributor Author

ianks commented Oct 22, 2020

this task is beyond my current abilities for v8 and c++, so i won’t be able to implement. if anyone wants to take this on, have at it!!

@SamSaffron
Copy link
Collaborator

@ianks I know it has been quite a few years, but our new design handles all of this now, we should be good.

@SamSaffron SamSaffron closed this Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants